package com.rk.topN;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class ViewCountBean implements WritableComparable<ViewCountBean> {

    private long docId;
    private long viewTotalCount;

    public ViewCountBean() {
        super();
    }

    public int compareTo(ViewCountBean o) {
       int result;
       if(this.viewTotalCount > o.getViewTotalCount()){
           result = -1;
       }else if(this.viewTotalCount < o.getViewTotalCount()){
           result = 1;
       }else{
           result = 0;
       }
       return result;
    }

    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeLong(docId);
        dataOutput.writeLong(viewTotalCount);
    }

    public void readFields(DataInput dataInput) throws IOException {
        this.docId = dataInput.readLong();
        this.viewTotalCount = dataInput.readLong();
    }

    public long getDocId() {
        return docId;
    }

    public void setDocId(long docId) {
        this.docId = docId;
    }

    public long getViewTotalCount() {
        return viewTotalCount;
    }

    public void setViewTotalCount(long viewTotalCount) {
        this.viewTotalCount = viewTotalCount;
    }

    @Override
    public String toString() {
        return this.viewTotalCount + "\r\n";
    }
}
